package ch.mustaffah.aoide.player;

import org.jfugue.Pattern;

import ch.mustaffah.aoide.ext.player.JFuguePlayer;
import ch.mustaffah.aoide.gui.MainApplicationFrame;
import ch.mustaffah.aoide.gui.VelocityMode;

public class PerpetuumPlayer extends Thread {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private int frequence=0;
	private String playString0="";
	private String playString1="";
	private MainApplicationFrame mainFrame;
	private VelocityMode velocity;

	public String getPlayString0() {
		return playString0;
	}


	public void setPlayString0(String playSting) {
		this.playString0 = playSting;
	}

	public String getPlayString1() {
		return playString1;
	}


	public void setPlayString1(String playSting) {
		this.playString1 = playSting;
	}
	

	public PerpetuumPlayer(MainApplicationFrame mainFrame) {
		this.mainFrame=mainFrame;
	}


	@Override
	public void run() {
		JFuguePlayer player = new JFuguePlayer();
		while (true) {
			int playLength=this.mainFrame.getPhraseLengthSlider().getValue();
			this.playString0=this.mainFrame.getAoideKeyBord0().getCurrentMusicString(playLength,this.mainFrame.getRandomRhythmCheckBox().isSelected(),this.mainFrame.getAoideKeyBord0().getTimeSelection());
			try {
				Pattern pattern=new Pattern();
				this.velocity=(VelocityMode)this.mainFrame.getVelocitySelection().getSelectedItem();
				pattern.add( "T["+velocity+"] " );
				pattern.add("V0 " + playString0);
				pattern.add("V1 " + playString1);
				player.setPlayPattern(pattern);
				player.play();
				Thread.sleep(frequence);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}

		}
	}

}
